STEP 4: Using randomFromList to Play a Random Groovoid

Groovoids are an easy way to sonify a Web page because they are built right into the Beatnik Player's soundbank and can start playing immediately. Groovoids are also free to use for any Web page author. This example makes use of JavaScript to randomly select one of the many Groovoids that are built into the soundbank. Each time you reload this page, a new randomly selected Groovoid will play.

NOTE  Because the selection is truly random, you may sometimes get the same Groovoid selected twice in a row.

Copy-and-Paste
<SCRIPT SRC="music-object.js"></SCRIPT>
<SCRIPT SRC="music-object-x-dynamic.js"></SCRIPT>

<SCRIPT LANGUAGE=JavaScript><!-- //

groovoidToPlay = Music.randomFromList (
   'Hits-BlastOff',
   'Hits-LudwigVan',
   'Hits-ZoomAndHit',
   'Fanfare-CorpSting1',
   'Fanfare-Majesty',
   'Misc-CashRegister',
   'UI-TeletypeBurst2'
);

Music.magicEmbed (
   'SRC="stub.rmf" ' +
   'GROOVOID="' + groovoidToPlay + '" ' +
   'AUTOSTART=TRUE ' +
   'DISPLAY=SONG ' +
   'MODE=INFO ' +
   'LOOP=FALSE ' +
   'VOLUME=100'
);

// --></SCRIPT>

Notice in the source code how we are now specifying Groovoid names instead of filenames in our call to the Music.randomFromList method.